<?php
	$files = scandir("online/");
	$num=count($files);
	$uid=$_GET['uid'];
	for($i=0;$i<$num;$i++)  {
		$fn = $files[$i];
		if(($fn != ".") && ($fn != "..")) {
			$stat = stat("online/$fn");
			if(time() - $stat['mtime'] > 30) {
				unlink("online/$fn");
				continue;
			}
		}
		
	}

	$files = scandir("online/");
	$num=count($files);
	$it=1000;
	$chosenCnt = 0;
	while($it-- && ($num != 2)) {
		$rnd = rand(0,$num-1);
		$fn=$files[$rnd];
		if(isset($chosen[$fn]))
			continue;
		else {
			if(($fn != ".") && ($fn != "..")) {
				$chosen[$fn]=1;
				$chosenCnt++;
			}
		}
		if(($chosenCnt >=5) || ($chosenCnt == ($num-2)))
			break;
		
	}

	//if($num <=7) {
	//	for($i=0;$i<$num;$i++) {
	//		if(($files[$i] != ".") && ($files[$i]!=".."))
	//			echo "online/".$files[$i]."<BR>";
	//	}
	//}
	//else {
	if(isset($chosen)) {
		foreach ($chosen as $key => $value) {
			$link= "online/".$key;
			#echo "<a href=\"$link\">$key</A><BR>";
			if($key!=$uid)
				echo "<a href=left.php?local=$uid&remote=$key>$key</a><BR>";
		}
	}
?>
